package com.baway.biliclitent.adapter;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.baway.biliclitent.R;
import com.baway.biliclitent.model.TomatoBotBean;
import com.baway.biliclitent.view.TomatoListView;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * 1.类的用途：番剧下方的适配器
 * 2.渠刚
 * 3.@date
 * 4.用途:
 */
public class MyTomBotAdapter extends RecyclerView.Adapter<MyTomBotAdapter.MyViewHolder>{
    private Context context;

    List<TomatoBotBean.ResultBean> resultList;
    public MyTomBotAdapter(Context context) {
        this.context = context;
    }
    public void setData(List<TomatoBotBean.ResultBean> resultList){
        this.resultList = resultList;
        this.notifyDataSetChanged();
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder myViewHolder = new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.tomato_bot_recy_item_layout,parent,false));
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.mImageLz.setImageDrawable(context.getResources().getDrawable(R.drawable.bangumi_home_ic_season_4));
        holder.mTeLZ.setText("番剧推荐");
        MyBaseAdapter myBaseAdapter = new MyBaseAdapter(context,resultList);
        holder.myTopListView.setAdapter(myBaseAdapter);
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        private final ImageView mImageLz;
        private final TextView mTeLZ;
        private final TomatoListView myTopListView;

        public MyViewHolder(View itemView) {
            super(itemView);
            mImageLz = (ImageView) itemView.findViewById(R.id.item_image_lz);
            mTeLZ = (TextView) itemView.findViewById(R.id.item_text_lz);
            myTopListView = (TomatoListView) itemView.findViewById(R.id.myTopListView);
        }
    }
    class MyBaseAdapter extends BaseAdapter{
        private Context context;
        List<TomatoBotBean.ResultBean> resultList;

        public MyBaseAdapter(Context context, List<TomatoBotBean.ResultBean> resultList) {
            this.context = context;
            this.resultList = resultList;
        }

        @Override
        public int getCount() {
            return resultList==null?0:resultList.size();
        }

        @Override
        public Object getItem(int i) {
            return resultList.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewHolder holder = null;
            if(view == null){
                view = LayoutInflater.from(context).inflate(R.layout.tomato_list_item_layout,null);
                holder = new ViewHolder();
                holder.list_iamge = (ImageView) view.findViewById(R.id.list_image);
                holder.list_nameTv = (TextView) view.findViewById(R.id.list_nameTv);
                holder.list_updateTv = (TextView) view.findViewById(R.id.list_updateTv);
                view.setTag(holder);
            }else{
                holder = (ViewHolder) view.getTag();
            }
            Glide.with(context).load(resultList.get(i).getCover()).into(holder.list_iamge);
            holder.list_nameTv.setText(resultList.get(i).getTitle());
            holder.list_updateTv.setText(resultList.get(i).getDesc());
            return view;
        }
        class ViewHolder{
            ImageView list_iamge;
            TextView list_nameTv,list_updateTv;
            CardView mCard;
        }
    }
}
